package cn.javase.base.internet._02_TCP通讯._单向通讯;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        try(ServerSocket server = new ServerSocket(9999)) {
            Socket socket = server.accept();
            while (true) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                String data;
                while ((data = reader.readLine()) != null) {
                    System.out.println("接受到的消息：" + data);
                    if (data.equals("bye")) {
                        break;
                    }
                }
                if ("bye".equals(data)) break;
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}
